from app import create_app, db
from flask_migrate import Migrate
from flask.cli import FlaskGroup

app = create_app()
migrate = Migrate(app, db)
cli = FlaskGroup(app)


@cli.command('init', help='Initialize the database.')
def init_db():
    db.create_all()
    print('Initialized the database.')
    add_admin()
    print('Added admin user.')


@cli.command('reinit', help='ReInitialize the database.')
def reinit_db():
    db.drop_all()
    print('Dropped all tables.')
    db.create_all()
    print('ReInitialized the database.')
    add_admin()
    print('Added admin user.')


def add_admin():
    from app.admin.models import Admin
    admin = Admin("root","root")
    db.session.add(admin)
    db.session.commit()


@cli.command('add_admin', help='Add admin user.')
def add_admin_cli():
    return add_admin


if __name__ == '__main__':
    cli()
    